package com.ruoyi.web.controller.system;

import com.ruoyi.common.annotation.Log;
import com.ruoyi.common.core.controller.BaseController;
import com.ruoyi.common.core.domain.AjaxResult;
import com.ruoyi.common.core.domain.entity.system.SysPintuanParentOrder;
import com.ruoyi.common.core.page.TableDataInfo;
import com.ruoyi.common.enums.BusinessType;
import com.ruoyi.common.utils.poi.ExcelUtil;
import com.ruoyi.system.service.ISysPintuanParentOrderService;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.security.access.prepost.PreAuthorize;
import org.springframework.web.bind.annotation.*;

import javax.servlet.http.HttpServletResponse;
import java.util.List;

/**
 * 小程序拼团订单父Controller
 *
 * @author zjw
 * @date 2023-08-29
 */
@RestController
@RequestMapping("/system/sysPintuanParentOrder")
public class SysPintuanParentOrderController extends BaseController {
    @Autowired
    private ISysPintuanParentOrderService sysPintuanParentOrderService;

    /**
     * 查询小程序拼团订单父列表
     */
    @PreAuthorize("@ss.hasPermi('system:order:list')")
    @GetMapping("/list")
    public TableDataInfo list(SysPintuanParentOrder sysPintuanParentOrder) {
        startPage();
        List<SysPintuanParentOrder> list = sysPintuanParentOrderService.selectSysPintuanParentOrderList(sysPintuanParentOrder);
        return getDataTable(list);
    }

    /**
     * 导出小程序拼团订单父列表
     */
    @PreAuthorize("@ss.hasPermi('system:order:export')")
    @Log(title = "小程序拼团订单父", businessType = BusinessType.EXPORT)
    @PostMapping("/export")
    public void export(HttpServletResponse response, SysPintuanParentOrder sysPintuanParentOrder) {
        List<SysPintuanParentOrder> list = sysPintuanParentOrderService.selectSysPintuanParentOrderList(sysPintuanParentOrder);
        ExcelUtil<SysPintuanParentOrder> util = new ExcelUtil<SysPintuanParentOrder>(SysPintuanParentOrder.class);
        util.exportExcel(response, list, "小程序拼团订单父数据");
    }

    /**
     * 获取小程序拼团订单父详细信息
     */
    @PreAuthorize("@ss.hasPermi('system:order:query')")
    @GetMapping(value = "/{orderId}")
    public AjaxResult getInfo(@PathVariable("orderId") String orderId) {
        return success(sysPintuanParentOrderService.selectSysPintuanParentOrderByOrderId(orderId));
    }

    /**
     * 新增小程序拼团订单父
     */
    @PreAuthorize("@ss.hasPermi('system:order:add')")
    @Log(title = "小程序拼团订单父", businessType = BusinessType.INSERT)
    @PostMapping
    public AjaxResult add(@RequestBody SysPintuanParentOrder sysPintuanParentOrder) {
        return toAjax(sysPintuanParentOrderService.insertSysPintuanParentOrder(sysPintuanParentOrder));
    }

    /**
     * 修改小程序拼团订单父
     */
    @PreAuthorize("@ss.hasPermi('system:order:edit')")
    @Log(title = "小程序拼团订单父", businessType = BusinessType.UPDATE)
    @PutMapping
    public AjaxResult edit(@RequestBody SysPintuanParentOrder sysPintuanParentOrder) {
        return toAjax(sysPintuanParentOrderService.updateSysPintuanParentOrder(sysPintuanParentOrder));
    }

    /**
     * 删除小程序拼团订单父
     */
    @PreAuthorize("@ss.hasPermi('system:order:remove')")
    @Log(title = "小程序拼团订单父", businessType = BusinessType.DELETE)
    @DeleteMapping("/{pintuanUseridss}")
    public AjaxResult remove(@PathVariable String[] pintuanUseridss) {
        return toAjax(sysPintuanParentOrderService.deleteSysPintuanParentOrderByPintuanUseridss(pintuanUseridss));
    }
}
